#-*-coding:utf-8-*-
import urllib.request as urlrequest
import ssl
import json
import ipinfo
def get_weather():
    host = 'https://jisutqybmf.market.alicloudapi.com'
    path = '/weather/query'
    method = 'GET'
    appcode = 'c107fd1045904365b1f739560bee3ae9'
    ip = ipinfo.get_ip()
    querys = "ip=" + str(ip)
    url = host + path + '?' + querys
    request = urlrequest.Request(url)
    request.add_header('Authorization', 'APPCODE ' + appcode)
    request.add_header('Content-Type', 'application/json; charset=UTF-8')
    ctx = ssl.create_default_context()
    ctx.check_hostname = False
    ctx.verify_mode = ssl.CERT_NONE
    response = urlrequest.urlopen(request, context=ctx)
    content = response.read()
    if (content):
        jsonData = content.decode()
        text = json.loads(jsonData)
        result = text['result']
    return result
# print(get_weather())